const app = getApp();
const db = wx.cloud.database().collection("equipment")
Page({
  data: {
    equipmentDetail: {},
    markers: [],
    scale: 16, // 缩放级别
    
  },
  onLoad: function(options) {
    
    const equipmentId = options.id; // 假设设备ID存储在页面参数中的 id 字段中
    this.getEquipmentDetail(equipmentId);
    // 初始化地图
    this.mapCtx = wx.createMapContext("myMap");
  },
  
  getEquipmentDetail: function(id) {
    db.doc(id).get().then(res => {
      let equipmentDetail = res.data;

      // 对 equipmentDetail 中的 cityText 进行排序
      equipmentDetail.equipment.sort((a, b) => {
        const order = {
          "摄像机及套件": 1,
          "镜头": 2,
          "稳定设备": 3,
          "灯光及配件": 4,
          "收音设备": 5,
          "其他": 6,
        };
        return order[a.cityText] - order[b.cityText];
      });

      // 创建 marker
      const marker = {
        id: 1,
        latitude: equipmentDetail.location2[1],
        longitude: equipmentDetail.location2[0],
        title: equipmentDetail.cname,
      };

      const markers = [marker];

      // 设置页面数据
      this.setData({
        equipmentDetail,
        markers
      });
    }).catch(err => {
      console.error('Failed to fetch equipment details', err);
    });
  }
});
